The where procedure provides a method of examining and modifying environments. Where is a procedure of 0 or 1 arguments that enters a read-execute command loop when called. Unlike a REP loop, this loop reads one letter and treats it as a command to be performed. Scheme will prompt for the one-character command at the bottom of the screen in the Emacs echo area. To give a command, just type the character—you needn't press RETURN.
If called with no arguments, where examines the current REP loop environment. The optional argument can be an environment or an object with an environment associated with it, such as a procedure. Below is an example of where being called at a breakpoint in a Scheme procedure. This illustrates some of the things which can be done with where.
While the where procedure is a very useful debugging aid, using it effectively requires a good understanding of Scheme's environment structures. For this reason you may find it less confusing to use only the C command initially.
Here is a brief description of each where command.
Here is an example of using where. The indicators at the left
of the user input show the information that would appear in the buffer
mode line, and in the prompts in the echo area:
The C command prints the variable bindings in the currently selected environment frame. Since the breakpoint occurred inside the execution of the procedure three, the current environment is the one resulting from the application of C to the arguments 1 2 3.
The P command moves to the frame in which three was defined. In
this case the parent is the frame created by the application of the
procedure two to the arguments 4 5 6.
Here we have reached the user initial environment in which the top
most procedure one was defined. That's enough …
and we are back in the REP loop where we started. We can continue
the program by typing (proceed).
Notice that we could stop at any environment and create a REP loop in it by using the E command. This allows you, for example, to define missing variables when you encounter an unbound variable error. Similarly, you can use the V (one expression) command to evaluate a single expression in any of the frames in the environment chain.